import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 创建一个固定大小的线程池
 */
public class ThreadPoolDemo1 {
    public static void main(String[] args) {
        // 创建一个线程个数为5的固定大小的线程池
        ExecutorService threadPool = Executors.newFixedThreadPool(5);
        for (int i = 0; i < 5; i++) {
            threadPool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("线程名称：" + Thread.currentThread().getName());
                }
            });
        }

        // 使用线程池执行任务2
        for (int i = 0; i < 10; i++) {
            // 给线程池添加任务
            threadPool.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("线程名称：" + Thread.currentThread().getName());
                }
            });
        }
    }
}
